/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package views;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.Enumeration;
import javax.swing.AbstractButton;
import javax.swing.ButtonGroup;
import javax.swing.ImageIcon;

/**
 *
 * @author dennis
 */
public class MenuPanel extends javax.swing.JPanel {

    /**
     * Creates new form MenuPanel
     */
    public MenuPanel() {
               
        initComponents();
        
    }
   
    public void addStartActionListener(ActionListener a) {
        jStartButton.addActionListener(a);
    }
    
    public void addLevelPickerActionListener(ActionListener a) {
        jLevelPicker.addActionListener(a);
    }
    
    public void addChildToggleActionListener(ActionListener a) {
        jToggleChildOn.addActionListener(a);
        jToggleChildOff.addActionListener(a);
    }
    
    public void addUndoActionListener(ActionListener a) {
        jUndo.addActionListener(a);
    }
    
    /**
     * Find the selected level in the dropdownbox
     * @return name of selected level
     */
    public String getSelectedLevel(){
        return (String) jLevelPicker.getSelectedItem();
    }
    
    /**
     * Adds levels to the dropdownbox
     * @param levels 
     */
    public void addLevelsToPicker(String[] levels){
        jLevelPicker.setModel(new javax.swing.DefaultComboBoxModel(levels));
    }
    
    /**
     * Update the stepcounter
     * @param steps 
     */
    public void updateSteps(int steps){
        jStepsCounter.setText(Integer.toString(steps));
    }
    
    /**
     * This is called when we start or restart a level, set's the steps back to zero
     */
    public void resetSteps(){
        jStepsCounter.setText("0");
    }
    
    /*
     * Update the progessbar with the current progress
     */
    public void setProgress(int progress){
        jProgressBar1.setValue(progress);
    }
    
    /**
     * Sets childmode to off, that's the default
     */
    public void defaultChildMode(){
        jToggleChildOff.setSelected(true);
        
        group = new ButtonGroup();
        group.add(jToggleChildOff);
        group.add(jToggleChildOn);
    }
    
    /**
     * Selected childmode 
     * @return On or Off
     */
    public String getSelectedChildMode(){
        return getSelectedButtonText(group);
    }
    
    /**
     * Finds the selected button in thie buttonGroup
     * @param buttonGroup
     * @return 
     */
    public String getSelectedButtonText(ButtonGroup buttonGroup) {
        for (Enumeration<AbstractButton> buttons = buttonGroup.getElements(); buttons.hasMoreElements();) {
            AbstractButton button = buttons.nextElement();

            if (button.isSelected()) {
                return button.getText();
            }
        }

        return null;
    }
    
    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jStartButton = new javax.swing.JButton();
        jLevelPicker = new javax.swing.JComboBox();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jName = new javax.swing.JTextField();
        jLabel3 = new javax.swing.JLabel();
        jProgressBar1 = new javax.swing.JProgressBar();
        jStepsCounter = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jToggleChildOn = new javax.swing.JRadioButton();
        jToggleChildOff = new javax.swing.JRadioButton();
        jUndo = new javax.swing.JButton();

        jStartButton.setText("Start");

        jLevelPicker.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jLevelPicker.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jLevelPickerActionPerformed(evt);
            }
        });

        jLabel1.setText("Pick a level:");

        jLabel2.setText("Hi, what is your name?");

        jLabel3.setText("Steps:");

        jStepsCounter.setText("0");

        jLabel5.setText("Childmode:");

        jToggleChildOn.setText("On");
        jToggleChildOn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToggleChildOnActionPerformed(evt);
            }
        });

        jToggleChildOff.setText("Off");

        jUndo.setText("undo");
        jUndo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jUndoActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addComponent(jLevelPicker, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                .addComponent(jLabel2)
                                .addComponent(jLabel1)
                                .addComponent(jStartButton, javax.swing.GroupLayout.DEFAULT_SIZE, 164, Short.MAX_VALUE)
                                .addComponent(jName)
                                .addComponent(jProgressBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                            .addComponent(jLabel5)
                            .addComponent(jUndo)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(22, 22, 22)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jStepsCounter))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(16, 16, 16)
                        .addComponent(jToggleChildOn)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jToggleChildOff)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(24, 24, 24)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jName, javax.swing.GroupLayout.PREFERRED_SIZE, 28, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(26, 26, 26)
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLevelPicker, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(22, 22, 22)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jToggleChildOn)
                    .addComponent(jToggleChildOff))
                .addGap(18, 18, 18)
                .addComponent(jStartButton, javax.swing.GroupLayout.PREFERRED_SIZE, 36, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 23, Short.MAX_VALUE)
                .addComponent(jUndo)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jStepsCounter)
                    .addComponent(jLabel3))
                .addGap(165, 165, 165)
                .addComponent(jProgressBar1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(72, 72, 72))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jLevelPickerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jLevelPickerActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jLevelPickerActionPerformed

    private void jToggleChildOnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToggleChildOnActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jToggleChildOnActionPerformed

    private void jUndoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jUndoActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jUndoActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JComboBox jLevelPicker;
    private javax.swing.JTextField jName;
    private javax.swing.JProgressBar jProgressBar1;
    private javax.swing.JButton jStartButton;
    private javax.swing.JLabel jStepsCounter;
    private javax.swing.JRadioButton jToggleChildOff;
    private javax.swing.JRadioButton jToggleChildOn;
    private javax.swing.JButton jUndo;
    // End of variables declaration//GEN-END:variables
    
    private ButtonGroup group;
    
    @Override
    public void paint(Graphics g){
        super.paint(g);
        /* Hmm, this does weird stuff to the menu...
        URL loc = this.getClass().getResource("../images/bg2.jpg");
        ImageIcon iia = new ImageIcon(loc);
        Image image = iia.getImage();
        g.drawImage(image,0, 0, this);
        */
    }

}


